﻿using MCPlatform.MotionLib.Base.Models;
using MCPlatform.MotionLib.Base;
using MCPlatform.UI.Controls.Models;
using Panuon.WPF;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;

namespace MCPlatform.Models
{
    public class CylinderModel : NotifyPropertyChangedBase
    {
        #region Properties
        public IValve? ValveEntity
        {
            get => _ValveEntity;
            set { Set(ref _ValveEntity, value); Initial(); }
        }
        private IValve? _ValveEntity;
        public ValveModel ValveModel { get => _ValveModel; set => Set(ref _ValveModel, value); }
        private ValveModel _ValveModel = new ValveModel();

        public ValveParaModel ValveParaModel { get => _ValveParaModel; set => Set(ref _ValveParaModel, value); }
        private ValveParaModel _ValveParaModel = new ValveParaModel();

        #endregion

        #region Methods

        Timer timer;
        public void StartMappingEntityToModel()
        {
            if (ValveEntity is null)
            {
                return;
            }

            timer.Start();


        }


        public void StopMappingEntityToModel()
        {

            timer.Stop();


        }

        #endregion

        #region CTOR

        public CylinderModel()
        {
            timer = new Timer(200);
            timer.Elapsed += Timer_Elapsed;


        }


        private void Timer_Elapsed(object? sender, ElapsedEventArgs e)
        {

            ValveParaModel.ValveEntity = ValveEntity;
            ValveModel.ValveEntity = ValveEntity;

            ValveModel.Mapping();


        }

        public void Initial()
        {
            ValveParaModel.ValveEntity = ValveEntity;
            ValveModel.ValveEntity = ValveEntity;
        }
        #endregion
    }
}
